<?php

/**
*+----------IMBA战队业务数据的获取操作-------------+
*+-------------------------------------------------+
*+-----------用于内部数据接口----------------------+
*+-------------------------------------------------+
*+-@author susy.liang <liangling@ilongyuan.com.cn>-+
*+-------------------------------------------------+
*/

namespace Api\Event;

class TeamEvent extends BaseEvent {

	protected $mod;

	protected function _initialize(){
		parent::_initialize();
		$this->mod = D('Common/Team', 'Service');
	}

	// 获取某一战队信息
	public function info($id = 0, $field='', $logoFormat=true)
	{
		$data = $this->mod->field($field)->find($id);

		unset($data['_id']);
		if($logoFormat)
			uri_format($data['logo']);

		return $data;
	}

	/**
	*根据战队名称获取信息
	*@param string $name 战队名
	*@param string $field 字段项， 默认所有
	*@return array
	*/
	public function infoByName($name='', $field=''){

		$data = $this->mod->where(array('name'=>(string)$name))->field($field)->find();
		unset($data['_id']);
		if($data['logo']){
			uri_format($data['logo']);
		}
		return $data;
	}

	/**
	*根据筛选条件获取战队列表
	*@param array $filter 过滤条件
	*@param int $limit 返回的条数
	*@return array 资源数据
	*@author susy<susy.liang@ilongyuan.com.cn>
	*/
	public function lists($filter=array(), $limit=0){

    	$map = array('status'=>array('egt', 0));
    	if($filter)
    		$map = array_merge($map, $filter);

    	$resource = $this->mod->where($map);

    	if($limit)
    		$resource = $resource->limit($limit);
    	
    	$resource = $resource->order('create_time desc')->select();

    	return $resource;
    }
}